package com.zhanbo.zhanbowymusic.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.mwx.baselib.utils.PixelUtil;
import com.mwx.baselib.utils.ToastUtils;
import com.zhanbo.zhanbowymusic.R;
import com.zhanbo.zhanbowymusic.play.PlayListAdapter;

import java.util.ArrayList;

public class BuyVipDialog extends Dialog implements View.OnClickListener {
    private Context mContext;
    private TextView tv_user_agreement;
    private ImageView iv_close;
    private LinearLayout ll_vip_bg;
    private View view_che_zai_vip;
    private View view_hei_jiao_vip;
    public BuyVipDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        mContext =context;
        Window window = getWindow();

        if (window != null) {
            WindowManager.LayoutParams layoutParams = window.getAttributes();
            layoutParams.width = PixelUtil.dp2px(mContext,1100);
            layoutParams.height = PixelUtil.dp2px(mContext,700);
            window.setBackgroundDrawableResource(R.color.transparency);
            window.setAttributes(layoutParams);
            window.setGravity(Gravity.CENTER);
        }
        setCanceledOnTouchOutside(true);

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pop_buy_vip);
        initView();
        initData();
        initListener();
    }

    private void initListener() {
        iv_close.setOnClickListener(this);
        view_che_zai_vip.setOnClickListener(this);
        view_hei_jiao_vip.setOnClickListener(this);
    }

    private void initView() {
        tv_user_agreement= findViewById(R.id.tv_user_agreement);
        iv_close= findViewById(R.id.iv_close);
        ll_vip_bg=   findViewById(R.id.ll_vip_bg);
        view_che_zai_vip=   findViewById(R.id.view_che_zai_vip);
        view_hei_jiao_vip=   findViewById(R.id.view_hei_jiao_vip);
    }

    private void initData() {
        SpannableStringBuilder span = new SpannableStringBuilder();
        span.append("开通会员代表接受《会员协议》、《连续包月服务协议》");
        span.setSpan(new ForegroundColorSpan(mContext.getResources().getColor(R.color.color_text)),0,8, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        ClickableSpan clickableSpan = new ClickableSpan() {
            @Override

            public void onClick(@NonNull View view) {
                ToastUtils.showShortToast(mContext,"隐私政策");
            }

        };

        ClickableSpan clickableSpan2 = new ClickableSpan() {
            @Override

            public void onClick(@NonNull View view) {
                ToastUtils.showShortToast(mContext,"隐私政策");
            }

        };

//        span.setSpan(clickableSpan,0,4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//        span.setSpan(clickableSpan2,5,9, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        tv_user_agreement.setText(span);
    }

    @Override
    public void show() {
        super.show();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.iv_close:
                dismiss();
                break;
            case R.id.view_che_zai_vip:
                ll_vip_bg.setBackgroundResource(R.mipmap.chezai_vip);
                break;
            case R.id.view_hei_jiao_vip:
                ll_vip_bg.setBackgroundResource(R.mipmap.heijiao_vip);
                break;
        }
    }

}
